package com.guofen.controller.sjq;

import com.guofen.pojo.SjqCompostProduceInspection;
import com.guofen.pojo.SjqCompostProduceMaintenanceDay;
import com.guofen.pojo.SjqCompostProduceMaintenanceMonth;
import com.guofen.pojo.SjqCompostProduceMaintenanceWeek;
import com.guofen.service.sjq.SjqCompostProduceMaintenanceDayService;
import com.guofen.service.sjq.SjqCompostProduceMaintenanceWeekService;
import com.guofen.service.sjq.SjqCompostProduceMaintenanceMonthService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;


@RequestMapping("/shlj/sjqCompostProduceMaintenance")
@Controller
@Api(tags = "SjqCompostProduceMaintenanceController", description = "堆肥日周月保养")
public class SjqCompostProduceMaintenanceController {
    @Autowired
    private SjqCompostProduceMaintenanceDayService sjqCompostProduceMaintenanceDayService;
    @Autowired
    private SjqCompostProduceMaintenanceWeekService sjqCompostProduceMaintenanceWeekService;
    @Autowired
    private SjqCompostProduceMaintenanceMonthService sjqCompostProduceMaintenanceMonthService;

    //日保养
    @ApiOperation("添加记录_日保养_记录人")
    @RequestMapping(value = "/add_day_recorder",method = RequestMethod.POST)
    @ResponseBody
    public Result add_day_recorder(@ApiParam(name="equipment_name",value="设备名称",required=true) @RequestParam String equipment_name,
                               @ApiParam(name="maintenanceContent",value="保养内容",required=true) @RequestParam String maintenanceContent,
                               @ApiParam(name="isNormal",value="是否正常",required=true) @RequestParam String isNormal,
                               @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks,
                               @ApiParam(name="operator",value="操作人",required=true) @RequestParam String operator){
        if (sjqCompostProduceMaintenanceDayService.add_operator(equipment_name,maintenanceContent,isNormal,operator,remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("添加记录_日保养_检察人")
    @RequestMapping(value = "/add_day_inspector",method = RequestMethod.POST)
    @ResponseBody
    public Result add_day_inspector(@ApiParam(name="id",value="id",required=true) @RequestParam String id,
                                @ApiParam(name="Inspector",value="记录人",required=true) @RequestParam String Inspector,
                                @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks){

        if (sjqCompostProduceMaintenanceDayService.add_inspector(id,Inspector,remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("获取 当日 日保养记录")
    @RequestMapping(value = "/getlast_day",method = RequestMethod.POST)
    @ResponseBody
    public Result getlast_day(@ApiParam(name="equipment_name",value="设备名称",required=true) @RequestParam String equipment_name,
                              @ApiParam(name="maintenanceContent",value="保养内容",required=true) @RequestParam String maintenanceContent){
        return  ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceDayService.getlast(equipment_name,maintenanceContent));
    }

    @ApiOperation("获取 当日 所有日保养记录")
    @RequestMapping(value = "/getDailyRecords",method = RequestMethod.GET)
    @ResponseBody
    public Result getDailyRecords(){
        return  ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceDayService.getDailyRecords());
    }

    @ApiOperation("检查多个设备日保养是否保养完毕")
    @RequestMapping(value = "/is_day_complete",method = RequestMethod.POST)
    @ResponseBody
    public Result is_day_complete(@ApiParam(name="equipmentsName",value="设备名称",required=true) @RequestParam String equipmentsName,
                                   @ApiParam(name="menstanceNum",value="保养方法数量",required=true) @RequestParam String menstanceNum,
                                   @ApiParam(name="role",value="角色(operator/examiner)",required=true) @RequestParam String role){
        return  ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceDayService.is_last_complete(equipmentsName,menstanceNum,role));
    }

    //周保养
    @ApiOperation("添加记录_周保养_记录人")
    @RequestMapping(value = "/add_week_recorder",method = RequestMethod.POST)
    @ResponseBody
    public Result add_week_recorder(@ApiParam(name="equipment_name",value="设备名称",required=true) @RequestParam String equipment_name,
                               @ApiParam(name="maintenanceContent",value="保养内容",required=true) @RequestParam String maintenanceContent,
                               @ApiParam(name="isNormal",value="是否正常",required=true) @RequestParam String isNormal,
                               @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks,
                               @ApiParam(name="operator",value="操作人",required=true) @RequestParam String operator){
        if (sjqCompostProduceMaintenanceWeekService.add_operator(equipment_name,maintenanceContent,isNormal,operator,remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("添加记录_周保养_检察人")
    @RequestMapping(value = "/add_week_inspector",method = RequestMethod.POST)
    @ResponseBody
    public Result add_week_inspector(@ApiParam(name="id",value="id",required=true) @RequestParam String id,
                                @ApiParam(name="Inspector",value="记录人",required=true) @RequestParam String Inspector,
                                @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks){

        if (sjqCompostProduceMaintenanceWeekService.add_inspector(id,Inspector,remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("获取 本周 周保养记录")
    @RequestMapping(value = "/getlast_week",method = RequestMethod.POST)
    @ResponseBody
    public Result getlast_week(@ApiParam(name="equipment_name",value="设备名称",required=true) @RequestParam String equipment_name,
                               @ApiParam(name="maintenanceContent",value="保养内容",required=true) @RequestParam String maintenanceContent){
        return  ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceWeekService.getlast(equipment_name,maintenanceContent));
    }

    @ApiOperation("获取 当周 所有周保养记录")
    @RequestMapping(value = "/getWeekRecords",method = RequestMethod.GET)
    @ResponseBody
    public Result getWeekRecords(){
        return  ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceWeekService.getWeekRecords());
    }

    @ApiOperation("检查多个设备周保养是否保养完毕")
    @RequestMapping(value = "/is_week_complete",method = RequestMethod.POST)
    @ResponseBody
    public Result is_week_complete(@ApiParam(name="equipmentsName",value="设备名称",required=true) @RequestParam String equipmentsName,
                                    @ApiParam(name="menstanceNum",value="保养方法数量",required=true) @RequestParam String menstanceNum,
                                    @ApiParam(name="role",value="角色(operator/examiner)",required=true) @RequestParam String role){
        return  ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceWeekService.is_last_complete(equipmentsName,menstanceNum,role));
    }

    //月保养
    @ApiOperation("添加记录_月保养_记录人")
    @RequestMapping(value = "/add_month_recorder",method = RequestMethod.POST)
    @ResponseBody
    public Result add_month_recorder(@ApiParam(name="equipment_name",value="设备名称",required=true) @RequestParam String equipment_name,
                                    @ApiParam(name="maintenanceContent",value="保养内容",required=true) @RequestParam String maintenanceContent,
                                    @ApiParam(name="isNormal",value="是否正常",required=true) @RequestParam String isNormal,
                                    @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks,
                                    @ApiParam(name="operator",value="操作人",required=true) @RequestParam String operator){
        if (sjqCompostProduceMaintenanceMonthService.add_operator(equipment_name,maintenanceContent,isNormal,operator,remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("添加记录_月保养_检察人")
    @RequestMapping(value = "/add_month_inspector",method = RequestMethod.POST)
    @ResponseBody
    public Result add_month_inspector(@ApiParam(name="id",value="id",required=true) @RequestParam String id,
                                     @ApiParam(name="Inspector",value="记录人",required=true) @RequestParam String Inspector,
                                     @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks){

        if (sjqCompostProduceMaintenanceMonthService.add_inspector(id,Inspector,remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }

    @ApiOperation("获取 当月 月保养记录")
    @RequestMapping(value = "/getlast_month",method = RequestMethod.POST)
    @ResponseBody
    public Result getlast_month(@ApiParam(name="equipment_name",value="设备名称",required=true) @RequestParam String equipment_name,
                                @ApiParam(name="maintenanceContent",value="保养内容",required=true) @RequestParam String maintenanceContent){
        return  ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceMonthService.getlast(equipment_name,maintenanceContent));
    }

    @ApiOperation("获取 当月 某设备的所有保养记录")
    @RequestMapping(value = "/getMonthRecords",method = RequestMethod.POST)
    @ResponseBody
    public Result getMonthRecords(@ApiParam(name="equipment_name",value="设备名称",required=true) @RequestParam String equipment_name){
        return  ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceMonthService.getMonthRecords(equipment_name));
    }

    @ApiOperation("检查多个设备月保养是否保养完毕 ")
    @RequestMapping(value = "/is_month_complete",method = RequestMethod.POST)
    @ResponseBody
    public Result is_month_complete(@ApiParam(name="equipmentsName",value="设备名称",required=true) @RequestParam String equipmentsName,
                                    @ApiParam(name="menstanceNum",value="保养方法数量",required=true) @RequestParam String menstanceNum,
                                    @ApiParam(name="role",value="角色(operator/examiner)",required=true) @RequestParam String role){
        return  ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceMonthService.is_last_complete(equipmentsName,menstanceNum,role));
    }

    @ApiOperation("获取至今保存的 日、周、月 保养内容数量")
    @RequestMapping(value = "/getMaintenanceNum", method = RequestMethod.GET)
    @ResponseBody
    public Result getMaintenanceNum() {
        int daily = sjqCompostProduceMaintenanceDayService.getInToday();
        int week = sjqCompostProduceMaintenanceWeekService.getInThisWeek();
        int month = sjqCompostProduceMaintenanceMonthService.getInThisMonth();
        Map<String, Object> map = new HashMap<>();
        map.put("daily", daily);
        map.put("week", week);
        map.put("month", month);
        return ResultGenerator.genSuccessResult(map);
    }

    @ApiOperation("删除记录_每日")
    @RequestMapping(value = "/delete_day",method = RequestMethod.POST)
    @ResponseBody
    public Result delete_day(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceDayService.delete(id));
    }

    @ApiOperation("修改记录_每日")
    @RequestMapping(value = "/update_day",method = RequestMethod.POST)
    @ResponseBody
    public Result update_day(@ApiParam(name="id",value="id",required=true) @RequestParam(required = true) Integer id,
                             @ApiParam(name="date",value="date",required=false) @RequestParam(required = false) String date,
                             @ApiParam(name="equipment_name",value="equipment_name",required=false) @RequestParam(required = false) String equipment_name,
                             @ApiParam(name="maintenance_content",value="maintenance_content",required=false) @RequestParam(required = false) String maintenance_content,
                             @ApiParam(name="is_normal",value="is_normal",required=false) @RequestParam(required = false) String is_normal,
                             @ApiParam(name="operator",value="operator",required=false) @RequestParam(required = false) String operator,
                             @ApiParam(name="inspector",value="inspector",required=false) @RequestParam(required = false) String inspector,
                             @ApiParam(name="remarks",value="remarks",required=false) @RequestParam(required = false) String remarks
    ) {
        SjqCompostProduceMaintenanceDay record = new SjqCompostProduceMaintenanceDay();

        record.setId(id);
        record.setDate(date);
        record.setEquipmentName(equipment_name);
        record.setMaintenanceContent(maintenance_content);
        record.setIsNormal(is_normal);
        record.setOperator(operator);
        record.setInspector(inspector);
        record.setRemarks(remarks);

        return ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceDayService.update(record));
    }

    @ApiOperation("查找记录_每日")
    @RequestMapping(value = "/select_day",method = RequestMethod.POST)
    @ResponseBody
    public Result select_day(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间(时间戳：毫秒)",required = false) @RequestParam(required = false) Long startTime,
                         @ApiParam(name="endTime",value="截止时间(时间戳：毫秒)", required = false) @RequestParam(required = false) Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceDayService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceDayService.getByTime(pageSize, currentPage, startTime, endTime));
    }


    @ApiOperation("删除记录_每月")
    @RequestMapping(value = "/delete_month",method = RequestMethod.POST)
    @ResponseBody
    public Result delete_month(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceMonthService.delete(id));
    }

    @ApiOperation("修改记录_每月")
    @RequestMapping(value = "/update_month",method = RequestMethod.POST)
    @ResponseBody
    public Result update_month(@ApiParam(name="id",value="id",required=true) @RequestParam(required = true) Integer id,
                               @ApiParam(name="date",value="date",required=false) @RequestParam(required = false) String date,
                               @ApiParam(name="maintenance_time_plan",value="maintenance_time_plan",required=false) @RequestParam(required = false) String maintenance_time_plan,
                               @ApiParam(name="maintenance_time_implement",value="maintenance_time_implement",required=false) @RequestParam(required = false) String maintenance_time_implement,
                               @ApiParam(name="equipment_name",value="equipment_name",required=false) @RequestParam(required = false) String equipment_name,
                               @ApiParam(name="maintenance_content",value="maintenance_content",required=false) @RequestParam(required = false) String maintenance_content,
                               @ApiParam(name="is_normal",value="is_normal",required=false) @RequestParam(required = false) String is_normal,
                               @ApiParam(name="operator",value="operator",required=false) @RequestParam(required = false) String operator,
                               @ApiParam(name="inspector",value="inspector",required=false) @RequestParam(required = false) String inspector,
                               @ApiParam(name="remarks",value="remarks",required=false) @RequestParam(required = false) String remarks
    ) {
        SjqCompostProduceMaintenanceMonth record = new SjqCompostProduceMaintenanceMonth();

        record.setId(id);
        record.setDate(date);
        record.setMaintenanceTimePlan(maintenance_time_plan);
        record.setMaintenanceTimeImplement(maintenance_time_implement);
        record.setEquipmentName(equipment_name);
        record.setMaintenanceContent(maintenance_content);
        record.setIsNormal(is_normal);
        record.setOperator(operator);
        record.setInspector(inspector);
        record.setRemarks(remarks);

        return ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceMonthService.update(record));
    }

    @ApiOperation("查找记录_每月")
    @RequestMapping(value = "/select_month",method = RequestMethod.POST)
    @ResponseBody
    public Result select_month(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                             @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                             @ApiParam(name="startTime",value="开始时间(时间戳：毫秒)",required = false) @RequestParam(required = false) Long startTime,
                             @ApiParam(name="endTime",value="截止时间(时间戳：毫秒)", required = false) @RequestParam(required = false) Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceMonthService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceMonthService.getByTime(pageSize, currentPage, startTime, endTime));
    }


    @ApiOperation("删除记录_每周")
    @RequestMapping(value = "/delete_week",method = RequestMethod.POST)
    @ResponseBody
    public Result delete_week(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceWeekService.delete(id));
    }

    @ApiOperation("修改记录_每周")
    @RequestMapping(value = "/update_week",method = RequestMethod.POST)
    @ResponseBody
    public Result update_week(@ApiParam(name="id",value="id",required=true) @RequestParam(required = true) Integer id,
                              @ApiParam(name="date",value="date",required=false) @RequestParam(required = false) String date,
                              @ApiParam(name="maintenance_time_plan",value="maintenance_time_plan",required=false) @RequestParam(required = false) String maintenance_time_plan,
                               @ApiParam(name="maintenance_time_implement",value="maintenance_time_implement",required=false) @RequestParam(required = false) String maintenance_time_implement,
                               @ApiParam(name="equipment_name",value="equipment_name",required=false) @RequestParam(required = false) String equipment_name,
                               @ApiParam(name="maintenance_content",value="maintenance_content",required=false) @RequestParam(required = false) String maintenance_content,
                               @ApiParam(name="is_normal",value="is_normal",required=false) @RequestParam(required = false) String is_normal,
                               @ApiParam(name="operator",value="operator",required=false) @RequestParam(required = false) String operator,
                               @ApiParam(name="inspector",value="inspector",required=false) @RequestParam(required = false) String inspector,
                               @ApiParam(name="remarks",value="remarks",required=false) @RequestParam(required = false) String remarks
    ) {
        SjqCompostProduceMaintenanceWeek record = new SjqCompostProduceMaintenanceWeek();

        record.setId(id);
        record.setDate(date);
        record.setMaintenanceTimePlan(maintenance_time_plan);
        record.setMaintenanceTimeImplement(maintenance_time_implement);
        record.setEquipmentName(equipment_name);
        record.setMaintenanceContent(maintenance_content);
        record.setIsNormal(is_normal);
        record.setOperator(operator);
        record.setInspector(inspector);
        record.setRemarks(remarks);

        return ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceWeekService.update(record));
    }

    @ApiOperation("查找记录_每周")
    @RequestMapping(value = "/select_week",method = RequestMethod.POST)
    @ResponseBody
    public Result select_week(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                               @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                               @ApiParam(name="startTime",value="开始时间(时间戳：毫秒)",required = false) @RequestParam(required = false) Long startTime,
                               @ApiParam(name="endTime",value="截止时间(时间戳：毫秒)", required = false) @RequestParam(required = false) Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceWeekService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(sjqCompostProduceMaintenanceWeekService.getByTime(pageSize, currentPage, startTime, endTime));
    }



}
